<?php

use yii\helpers\Html;
use yii\grid\GridView;
use yii\widgets\ActiveForm;
use kartik\select2\Select2;
use yii\helpers\ArrayHelper;
/* @var $this yii\web\View */
/* @var $searchModel app\models\GkyWeWelcomeSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '微信欢迎语';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="gky-we-welcome-index">
    <!--     <div class="col-md-12">
    <?php
    $form = ActiveForm::begin([
                'action' => ['index'],
                'method' => 'get',
                'options' => ['class' => 'input-group'],
                'fieldConfig' => [
                    'template' => '<div class="col-lg-12">{input}</div>',
                ]
            ])
    ?>
    
            <div class="col-md-8">
                <label style="float: left;margin-top: 5px;">欢迎语</label>
                <div style="overflow: hidden;">
    <?php
//                $data = app\models\GkyWeWelcome::find()->all();
//                echo $form->field($searchModel, 'title')->widget(Select2::classname(), [
//                    'data' => ArrayHelper::map($data, 'title', 'title'),
//                    'options' => ['placeholder' => '请输入内容'],
//                    'pluginOptions' => [
//                        'allowClear' => true
//                    ],
//                ]);
    ?>
    <?php
    $projects = app\models\GkyWeWelcome::find()->all();
    foreach ($projects as $item) {
        $source[] = $item->title;
    }
    echo yii\jui\AutoComplete::widget([
        'model' => $searchModel,
        'attribute' => 'title',
        'options' => ['style' => 'margin-left:10px'],
        'clientOptions' => [
            'source' => $source,
        ],
    ]);
    ?>
                </div>
            </div>
    
    
            <div class="col-md-2 text-center">
    <?= Html::submitButton('搜索', ['class' => 'btn btn-primary']) ?>
            </div>
    
              <div class="col-md-2 text-center">
    <?= Html::a('新增欢迎语', ['create'], ['class' => 'btn btn-success']) ?>
              </div>
    
        </div>-->

    <div class="col-md-12 text-right" style="margin: 15px 0 15px 15px;">


    </div>

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
//        'filterModel' => $searchModel,
        'columns' => [
           // ['class' => 'yii\grid\SerialColumn'],

           // 'id',
            'weixin.wename',
            'title',
            'description',
//            'picUrl',
//            'jumpUrl',
            // 'createtime',
            'isSet' => [
                'attribute' => 'isSet',
                'label' => '设置状态',
                'format' => 'raw',
                'value'=>function ($model) {
                    if($model->isSet == 1){
                        return Html::label(
                            '已设置',
                            null,
                            ['class'=>'text-danger']
                        );
                    }else{
                        return Html::a(
                            "设置",
                            ['gky-we-welcome/set-welcome','id'=>$model->id],
                            ['class'=>"btn btn-xs btn-danger btn-block"]
                        );
                    }
                    
                },
             ],

            [
                'class' => 'yii\grid\ActionColumn',
                'template' => '{view} {update} {delete}',
//                'buttons' => [
//                    //view button
//                    'view' => function ($url) {
//                        return Html::a('<span class="fa fa-search"></span>查看', $url, [
//                                    'title' => Yii::t('app', 'View'),
//                                    'class' => 'btn btn-primary btn-xs',
//                        ]);
//                    },
//                            //update button
//                            'update' => function ($url) {
//                        return Html::a('<span class="fa fa-search"></span>更新', $url, [
//                                    'title' => Yii::t('app', 'Update'),
//                                    'class' => 'btn btn-primary btn-xs',
//                        ]);
//                    },
//                            //update button
//                            'delete' => function ($url) {
//                        return Html::a('<span class="fa fa-search"></span>删除', $url, [
//                                    'title' => Yii::t('app', 'Delete'),
//                                    'data-confirm' => Yii::t('yii', 'Are you sure you want to delete this item?'),
//                                    'data-method' => 'post',
//                                    'data-pjax' => '0',
//                                    'class' => 'btn btn-primary btn-xs',
//                        ]);
//                    },
//                ],
            ],
        ],
    ]); ?>

</div>
